﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.Unity;
using iTelluro.Explorer.Domain.MainBoundedContext;
using iTelluro.Explorer.Infrastructure.Data.MainBoundedContext;
using iTelluro.Explorer.Application.MainBoundContext;
using iTelluro.Explorer.Infrastructure.CrossCutting.Adapter;
using iTelluro.Explorer.Infrastructure.CrossCutting.Caching;
using iTelluro.Explorer.Infrastructure.CrossCutting.Logging;
using iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.Adapter;
using iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.Logging;
using iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.SSO;
using iTelluro.Explorer.Infrastructure.CrossCutting.NetFramework.Caching;
using iTelluro.Explorer.Infrastructure.CrossCutting.SSO;
using iTelluro.Explorer.Infrastructure.Data.MainBoundedContext.UnitOfWork;
using iTelluro.Explorer.Infrastructure.Data.Seedwork;
using iTelluro.Explorer.Infrastructure.Data.MainBoundedContext.Respository;
using iTelluro.Exporer.Application.MainBoundContext;

namespace iTelluro.Explorer.Program.InstanceProviders
{

    public static class Container
    {
        #region Properties

        static IUnityContainer _currentContainer;

        public static IUnityContainer Current
        {
            get { return _currentContainer; }
        }

        #endregion

        #region Constructor

        static Container()
        {
            ConfigureContainer();

            ConfigureFactories();
        }

        #endregion

        #region methods

        static void ConfigureContainer()
        {
            _currentContainer = new UnityContainer();

            string db = System.Configuration.ConfigurationManager.AppSettings["DBSchema"];
            _currentContainer.RegisterType<IQueryableUnitOfWork, WarningDataContext>();
            _currentContainer.RegisterType<IQueryableUnitOfWork, zybContent>();

            _currentContainer.RegisterType<IMetalertRepository, MetaDataRepository>();
            _currentContainer.RegisterType<IzhongyaobaoRepository, zhongyaobaoRepository>();

            _currentContainer.RegisterType<ImeteorologicalAppService, meteorologicalAppService>();
            _currentContainer.RegisterType<IzhongyaobaoAppService, zhongyaobaoAppService>();

            _currentContainer.RegisterType<ITypeAdapterFactory, AutomapperTypeAdapterFactory>(new ContainerControlledLifetimeManager());
        }

        static void ConfigureFactories()
        {
            LoggerFactory.SetCurrent(new Log4netFactory());//使用log4net
            var typeAdapterFactory = _currentContainer.Resolve<ITypeAdapterFactory>();
            TypeAdapterFactory.SetCurrent(typeAdapterFactory);
        }
        #endregion

    }
}